/* support.hh
* This file is part of ncursesxx library
* Copyright (c) 2003,2004 by Stanislav Ievlev
*
* This file is covered by the GNU Library General Public License,
* which should be included with libncursesxx as the file COPYING.
*/
#ifndef NCURSESXX_SUPPORT_HH__
#define NCURSESXX_SUPPORT_HH__

#include <algorithm>

namespace ncurses
{

	template <class T>
	class singleton_holder
	{ /**< simple Meyers' style singleton */
	public:
		typedef T obj_type;
		static T& instance() /**< @return instance of the object */
		{
			static T obj;
			return obj;
		}
	private:
		//all this operations are unavailable to ordinal users
		singleton_holder();
		singleton_holder(const singleton_holder& s);
		singleton_holder& operator=(const singleton_holder& s);
		~singleton_holder();
	};



	struct counter
	{ /**< object usage counter for shared objects */
		counter() : usage_(new int(1)) {}
		counter(const counter& other): usage_(other.usage_) { ++*usage_; }
		~counter() { if (0 == --*usage_) delete usage_; }
	void swap(counter& other) { std::swap(usage_, other.usage_); }
		int *usage_;
	};

}

#endif
